using Data;
using Framework.GamePool;
using Framework.UI;
using IcecreamView;
using UnityEngine;

public class GameLauncherCube : GameCube
{

    protected GameLight _gameLight;

    public override void Pool_Enable()
    {
        base.Pool_Enable();
        this._oldCube.Clear();
        this.transform.eulerAngles              = Vector3.zero;
        this.CurVector                          = LightVector.U;
        UIManager.Instance.EventManager.BindEvent(EventCode.CheckLight, this.Active);
    }

    public override void Pool_Disable()
    {
        if (this._gameLight)
        {
            this._gameLight.Pool_Disable();
            this._gameLight = null;
        }

        UIManager.Instance.EventManager.UnBindEvent(EventCode.CheckLight, this.Active);
        base.Pool_Disable();
    }

    private void Active(EventArg eventArg)
    {
        GamePoolMgr.Instance.DisableObjectWitchTable("GameLight");
        if (this._oldCube.Count > 0)
        {
            this._oldCube[0].OnCloseLight();
            this._oldCube.Clear();
        }
        
        this._gameLight                         = GamePoolMgr.Instance.InstantiatePoolObject<GameLight>("GameLight", this.transform);
        this._gameLight.transform.localPosition = Vector3.zero;
        var point = GameManager.Instance.GameRoom.ControlEndPoint(this.Point, LightVector.U);
        this._gameLight.UpdateLight(Point, point);
        if (GameManager.Instance.GameRoom.GridData.ContainsKey(point))
        {
            this._oldCube.Add(GameManager.Instance.GameRoom.GridData[point]);
            GameManager.Instance.GameRoom.GridData[point].OnInLight(LightVector.U);
        }
        GameManager.Instance.GameRoom.CheckReceiverCount();
        Debug.Log("当前激活数量 ： " + GameManager.Instance.GameRoom.ActiveCount);
    }
}